package com.ysalliance.getFan.organization.ui;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.ysalliance.getFan.organization.Bean.ClassBean;
import com.ysalliance.getFan.organization.R;
import com.ysalliance.getFan.organization.ui.base.LucasBaseActivity;

import butterknife.BindView;

import static com.ysalliance.getFan.organization.FanerConstant.CLASS_SHARE;


/**
 * 分享页面
 * @author lucas
 * created at 2020-02-24 14:54
 */
public class EnterCreateClassSuccessActivity extends LucasBaseActivity {

    //用户协议
    @BindView(R.id.tv_title)
    TextView tv_title;

    @BindView(R.id.tv_tag2)
    TextView tv_tag2;

    @BindView(R.id.img_share_weixin)
    ImageView img_share_weixin;  //微信分享



    public ClassBean classBean;


    @Override
    public int bindContentView() {
        return R.layout.activity_enter_create_class_success;
    }

    @Override
    public void afterView() {
        super.afterView();


        classBean = (ClassBean) getIntent().getSerializableExtra("class_info");

        tv_title.setText("分享");
        tv_tag2.setText(classBean.getCode());


        initClick();

    }


    public void initClick() {

        //微信分享
        img_share_weixin.setOnClickListener(v->{
            share(classBean);
        });



    }






    /**   友盟分享   */
    private UMShareListener umShareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
//            Toast.makeText(SecretSituationActivity.this, "成功了分享！", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            LogUtils.e("分享失败的回调", t.getMessage());
        }

        /**
         * @descrption 分享取消的回调
         * @param
         */
        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            LogUtils.e(TAG, "onCancel: ++++++++++++   这里是友盟分享的取消！");
        }
    };




    public void share(ClassBean classBean) {
        ShareBoardConfig config = new ShareBoardConfig();//新建ShareBoardConfig
        config.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                LogUtils.w(TAG, "友盟  ShareBoardConfig  onDismiss:------- ");

            }
        });
        UMImage image = new UMImage(mContext, R.mipmap.logo);//资源文件
        image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩，默认为大小压缩，适合普通很大的图


//        第一版的网页型分享！
        UMWeb web = new UMWeb(CLASS_SHARE + "?code="+classBean.getCode() );
        web.setTitle("邀请你加入起范儿【"+classBean.getName()+"】班级群");//标题
        web.setThumb(image);  //缩略图
        web.setDescription("每天打卡十分钟，学戏更轻松");//描述


        new ShareAction(mContext)
                .setPlatform(SHARE_MEDIA.WEIXIN)
                .setCallback(umShareListener)
                .withMedia(web)
                .share();

    }



}
